
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../css/ol.css" type="text/css" />
    <style>
        .map {
            height: 98%;
            width: 100%;
        }
    </style>
    <script src="../js/ol.js" type="text/javascript"></script>
    <title>OpenLayers example</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
    // var extent = [0, 0, 418, 600];
    // var projection = new ol.proj.Projection({
    //     code: 'xkcd-image',
    //     units: 'pixels',
    //     extent: extent
    // });
    // var map = new ol.Map({
    //     layers: [
    //         new ol.layer.Image({
    //             source: new ol.source.ImageStatic({
    //                 url: 'http://localhost:2265/images2/test1.png',//这里添加静态图片的地址
    //                 projection: projection,
    //                 imageExtent: extent
    //             })
    //         })
    //     ],
    //     target: 'map',
    //     view: new ol.View({
    //         projection: projection,
    //         center: ol.extent.getCenter(extent),
    //         zoom: 2,
    //         maxZoom: 8
    //     })
    // });


    // Map views always need a projection.  Here we just want to map image
    // coordinates directly to map coordinates, so we create a projection that uses
    // the image extent in pixels.
    var extent = [0, 0, 1024, 968];//图片图层四至
    var projection = new ol.proj.Projection({//定义坐标系
        code: 'xkcd-image',
        units: 'pixels',
        extent: extent
    });

    var map = new ol.Map({
        layers: [
            new ol.layer.Image({
                source: new ol.source.ImageStatic({
                    url: 'https://imgs.xkcd.com/comics/online_communities.png',//地址
                    projection: projection,
                    imageExtent: extent
                })
            })
        ],
        target: 'map',
        view: new ol.View({
            projection: projection,
            center: ol.extent.getCenter(extent),
            zoom: 2,
            maxZoom: 8
        })
    });
</script>
</body>
</html>